using System;
using System.Net;
using System.Net.Mail;
using System.Text;
namespace APP.HELPER.Utils.Net
{
	public class Email
	{
		private readonly MailMessage _message;
		private readonly SmtpClient _smtpClient;
		public string Subject
		{
			get
			{
				return this._message.Subject;
			}
			set
			{
				this._message.Subject = value;
			}
		}
		public bool IsHtml
		{
			get
			{
				return this._message.IsBodyHtml;
			}
			set
			{
				this._message.IsBodyHtml = value;
			}
		}
		public string Body
		{
			get
			{
				return this._message.Body;
			}
			set
			{
				this._message.Body = value;
			}
		}
		public Email(string yourMail, string yourName)
		{
			MailAddress from = new MailAddress(yourMail, yourName, Encoding.UTF8);
			this._smtpClient = new SmtpClient
			{
				Port = 25
			};
			this._message = new MailMessage
			{
				From = from,
				IsBodyHtml = true,
				BodyEncoding = Encoding.UTF8
			};
		}
		public void AddToAddress(string address, string name)
		{
			this._message.To.Add(new MailAddress(address, name, Encoding.UTF8));
		}
		public void Content(string subject, string textbody)
		{
			this._message.Subject = subject;
			this._message.Body = textbody;
		}
		public void AddBccAddress(string address, string name)
		{
			this._message.Bcc.Add(new MailAddress(address, name, Encoding.UTF8));
		}
		public void AddCcAddess(string address, string name)
		{
			this._message.CC.Add(new MailAddress(address, name, Encoding.UTF8));
		}
        public void AssignGmailSSL(string username, string password)
        {
            clsEmailOption clsEmailOption = new clsEmailOption();
            this._smtpClient.Host = clsEmailOption.Host;
            this._smtpClient.Port = clsEmailOption.Port;
            this._smtpClient.EnableSsl = clsEmailOption.EnableSSL;
            this._smtpClient.Credentials = new NetworkCredential(username, password);
        }
		public void AssignSslSmtp(string smtpServer, int port, string mailAddress, string password)
		{
			this._smtpClient.Host = smtpServer;
			this._smtpClient.Port = port;
			this._smtpClient.EnableSsl = true;
			this._smtpClient.Credentials = new NetworkCredential(mailAddress, password);
		}
		public void AssignSmtp(string smtp)
		{
			this._smtpClient.Host = smtp;
		}
		public void Send()
		{
			try
			{
				this._smtpClient.Send(this._message);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
        public void Attachment(Attachment att)
        {
            this._message.Attachments.Add(att);
        }
	}
}
